nki(histogramming): NKI (Trainium) implementation - #280
Open
bowencui123 wants to merge 9 commits into
Open
bowencui123 wants to merge 9 commits into
bowencui123 wants to merge 9 commits into
Conversation
Split out of the consolidated NKI branch cecilia/feature/nki-vector-add (nki-all-operators, PR #259) so each operator can be reviewed on its own. Supersedes PR #222 (older per-operator branch). - also carries the operator's `impl_torch.py` change from the NKI branch Co-Authored-By: Cecilia123li <68335867+Cecilia123li@users.noreply.github.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012Q38kGmXvyoeM1qtCbheSL
This was referenced Aug 29, 2026
Tunables mirror the Triton search space (`BLOCK_SIZE`/`BLOCK_ROWS`/`BLOCK_BINS`); defaults are the previous constants, so autotune=False is unchanged. Triton's bins/rows split has no NKI analog (histogram accumulates per partition) Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012Q38kGmXvyoeM1qtCbheSL
This branch's impl_torch.py already builds a CPU-safe reference (no CUDA-only assert), so this was just never actually benchmarked before. Adds results/csv/histogramming_default.csv: 20/20 cases pass correctness verification. Performance is notably poor (~0.02x avg vs. the torch-on-Neuron baseline, i.e. NKI is ~45-100x slower) -- expected given the kernel counts via broadcast-compare-per-bin rather than atomics (no atomic histogram primitive on this hardware), which is O(N * num_bins) work instead of O(N). Correct, just not fast. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AQseF7nyesBh8KZAp8g7Cm
… LNC2) Merges NKI backend timing into results/csv/histogramming_autotune.csv, run with --autotune against this branch's impl_nki.py on trn2.3xlarge, LNC2 execution contract. 19/20 cases pass correctness verification and are included. One case (N=67108864, num_bins=4096 int32) is excluded: neuronx-cc's backend scheduler/register-allocator (walrus_driver) took multiple hours to compile a single candidate for this shape and was killed rather than let run indefinitely. This is the operator's largest input combined with autotune re-compiling per candidate; the same shape compiles and runs correctly (just slowly, ~45-100x under the torch-on-Neuron baseline) under the default (non-autotune) config, where it's covered by results/csv/histogramming_default.csv. Root cause is very likely the fully-unrolled Python loop over ~524k partition tiles for this N generating an extremely large static program for the compiler backend, not a correctness defect -- every case that did complete verified correctly. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AQseF7nyesBh8KZAp8g7Cm
bowencui123
commented
Sep 11, 2026
| "N=67108864, num_bins=64",int32,0.7712,0.9464,1.8305,0.81,0.42,1.9342,7.8280,111.8305,0.07 | ||
| "N=67108864, num_bins=256",int32,0.6610,0.9612,1.8510,0.69,0.36,1.9257,7.8234,217.1039,0.04 | ||
| "N=67108864, num_bins=1024",int32,0.6350,0.9350,1.7902,0.68,0.35,1.9147,7.8260,870.1608,0.01 | ||
| "N=67108864, num_bins=4096",int32,0.6246,0.8009,1.4265,0.78,0.44,1.7810,,, |
Collaborator
Author
There was a problem hiding this comment.
Lost result for N=67108864, num_bins=4096
bowencui123
commented
Sep 11, 2026
# Conflicts: # results/csv/histogramming_autotune.csv # results/csv/histogramming_default.csv
… packed matmuls, exact int32 accumulation, per-core partials); on-device XLA torch baseline (bincount/histc run on the host); rerun benchmarks Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ScXYNjrrKGgDUVNHxv7HJt
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ScXYNjrrKGgDUVNHxv7HJt
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ScXYNjrrKGgDUVNHxv7HJt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
NKI (AWS Trainium) implementation of histogramming, split out of the consolidated NKI branch
cecilia/feature/nki-vector-add(nki-all-operators, #259) so each operator can be reviewed independently. Supersedes #222 (older per-operator branch: legacyneuronxcc.nkiimports; this is the migratedimport nkiversion).Files: A benchmarks/operators/histogramming/impl_nki.py, M benchmarks/operators/histogramming/impl_torch.py
Status: imports and exposes run()/get_last_config() on trn2 (nki 0.6.0); not individually re-benchmarked in this split
impl_torch.pychange from the NKI branchImplementation by @Cecilia123li. Timing/identity infrastructure: #261; Trainium peak/roofline infra: #262.
🤖 Generated with Claude Code
https://claude.ai/code/session_012Q38kGmXvyoeM1qtCbheSL
Autotune (47d2823)
block_size(values chunk per pass)BLOCK_SIZE/BLOCK_ROWS/BLOCK_BINSautotune=Falsekeeps the previous constants (default numbers unchanged). Validation on trn2, case 0 (default run + autotune code path with the candidate timer stubbed — no sweep;--autotuneruns a real sweep):